package pojo;


import db.ManageCarDB;

import java.util.*;

public class Collect {
    private User user;
    private List<Car> list;
    private ManageCarDB manageCarDB;

    public Collect(User user) {
        this.user = user;
       list = new ArrayList<>();
       manageCarDB = new ManageCarDB(list);
    }

    public List<Car> getList() {
        return list;
    }

    //操作list
    public boolean listAdd(Car car){
        if(list.size()>10){
            list.remove(0);
        }
        return manageCarDB.add(car);
    }
    public boolean listDelete(Car car){
        return manageCarDB.delete(car);
    }
    public List<Car> listFind(String field,String content){
        return manageCarDB.find(field, content);
    }
    public int listFind(Car car){
        return manageCarDB.find(car);
    }
    @Override
    public String toString() {
        return "Collect{" +
                "user=" + user +
                ", list=" + list +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Collect collect = (Collect) o;
        return Objects.equals(user, collect.user) &&
                Objects.equals(list, collect.list);
    }

    @Override
    public int hashCode() {
        return Objects.hash(user, list);
    }
}
